import java.util.Arrays;

public class Demo4_15 {
    //字符串的常用方法
    public static void main(String[] args) {
        String str1 = "abcd";
        //通过下标寻找字符串的对应字符
        char ch = str1.charAt(1);
        System.out.println(ch);

        //从前往后找，通过字符寻找它的对应下标  fromIndex表示从第几个位置查找字符
        int index = str1.indexOf('c', 1);
        System.out.println(index);
        int index1 = str1.indexOf("bc");
        System.out.println(index1);
        //从后往前找，通过字符寻找它的对应下标
        int index2 = str1.indexOf('d');
        System.out.println(index2);
        //将数值转换为字符串类型
        String s1 = String.valueOf(60);
        System.out.println(s1);
        //数值转换
        int data = Integer.parseInt("12");
        System.out.println(data + 2);
        double data1 = Double.valueOf("12.34");
        System.out.println(data1 + 2);
        //英语大小写转换
        String str2 = "ABC";
        String str3 = str2.toLowerCase();//不是在原字符串本身进行修改
        System.out.println(str3);
        String str4 = str1.toUpperCase();
        System.out.println(str4);

        //把字符串改为数组
        char[] ch1=str1.toCharArray();
        System.out.println(Arrays.toString(ch1));

        //格式化
        String s2 = String.format("%d-%d-%d",2024,3,21);
        System.out.println(s2);
    }
}
